
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
// #include <sys/types.h>

#include "heap.h"


void heap_test_main()
{	
	char *p = pvPortMalloc(1*1024);
	printf("[%s](%d) p=%x\n",__func__,__LINE__,p);

	sprintf(p,"malloc %d\r\n", 1*1024);
	printf("[%s](%d) p=%s\n",__func__,__LINE__,p);
	int heap_free = xPortGetFreeHeapSize();
	printf("[%s](%d) free=%x(%dk)\n",__func__,__LINE__,heap_free,heap_free/1024);

	char *p2 = pvPortMalloc(1*1024);
	printf("[%s](%d) p=%x\n",__func__,__LINE__,p2);
	sprintf(p2,"malloc %d\r\n", 1*1024);
	printf("[%s](%d) p=%s\n",__func__,__LINE__,p2);
	heap_free = xPortGetFreeHeapSize();
	printf("[%s](%d) free=%x(%dk)\n",__func__,__LINE__,heap_free,heap_free/1024);

	vPortFree(p);
	heap_free = xPortGetFreeHeapSize();
	printf("[%s](%d) free=%x(%dk)\n",__func__,__LINE__,heap_free,heap_free/1024);

	vPortFree(p2);
	heap_free = xPortGetFreeHeapSize();
	printf("[%s](%d) free=%x(%dk)\n",__func__,__LINE__,heap_free,heap_free/1024);
}